package com.yuexunit.finance.project.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.common.util.DateUtils;
import com.yuexunit.finance.project.entity.ReceiptRecordEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.persist.PersistUtil;

/**
*@version 创建时间：2018年1月9日 上午10:03:34
*@author wenwenlong
*类说明
*/

@Implements(ReceiptRecordService.class)
public class ReceiptRecordServiceImpl implements ReceiptRecordService {

	@Override
	public Long createReceiptRecord(ReceiptRecordEntity entity) {
		entity.setCreateDateTime(DateUtils.now());
		entity.setUpdateDateTime(DateUtils.now());
		entity.setEnabled(Boolean.TRUE);
		PersistUtil.insert(entity);
		return entity.getReceipRecordtId();
	}

	@Override
	public void updateReceiptRecord(ReceiptRecordEntity entity) {
		entity.setUpdateDateTime(DateUtils.now());
		PersistUtil.insert(entity);
	}

	@Override
	public void disableReceiptRecord(Long receiptRecordId) {
		ReceiptRecordEntity entity = PersistUtil.get(ReceiptRecordEntity.class, receiptRecordId);
		entity.setEnabled(Boolean.FALSE);
		entity.setUpdateDateTime(DateUtils.now());
		PersistUtil.update(entity);
	}

	@Override
	public ReceiptRecordEntity inquireReceiptRecord(Long receiptRecordId) {
		return PersistUtil.get(ReceiptRecordEntity.class, receiptRecordId);
	}

	@Override
	public List<ReceiptRecordEntity> inquireReceiptRecordList(Long settlementStatementId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(ReceiptRecordEntity.class);
		criteria.add(Restrictions.eq("enabled", Boolean.TRUE));
		if (settlementStatementId != null) {
			criteria.add(Restrictions.eq("settlementStatementId", settlementStatementId));
		}
		return PersistUtil.get(criteria);
	}

	@Override
	public PageList<ReceiptRecordEntity> inquireReceiptRecordPageList(Long settlementStatementId, PageCriteria page) {
		DetachedCriteria criteria = DetachedCriteria.forClass(ReceiptRecordEntity.class);
		criteria.add(Restrictions.eq("enabled", Boolean.TRUE));
		if (settlementStatementId != null) {
			criteria.add(Restrictions.eq("settlementStatementId", settlementStatementId));
		}
		return PersistUtil.get(criteria, page);
	}
}
